package com.ruoyi.api.controller;


import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * PDA登录
 */
@Api(value = "/api/unauth", description = "系统非登录操作基础接口")
@RestController
@RequestMapping("/api/unauth")
public class SystemApiController {


    @Autowired
    SysLoginService loginService;
    private String captchaType;

    @PostMapping("/showCode")
    @ApiOperation(value = "获取登录页是否展示验证码", notes = "")
    public AjaxResult showCode() {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        return AjaxResult.success(sysUser);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录接口")
    public AjaxResult ajaxLogin(String userName, String passWord) {
        LoginBody loginBody = new LoginBody();
        loginBody.setUsername(userName);
        loginBody.setPassword(passWord);
        AjaxResult ajax = AjaxResult.success();
        String token = loginService.loginWx(loginBody.getUsername(), loginBody.getPassword());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    @PostMapping("/loginOther")
    @ApiOperation("用户登录接口")
    public AjaxResult pajaxLogin(@RequestBody LoginBody loginBody) {
        AjaxResult ajax = AjaxResult.success();
        String token = loginService.loginWx(loginBody.getUsername(), loginBody.getPassword());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }
}
